package com.mef.smsplat.service;

import java.util.Date;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mef.smsplat.dao.SysAdminInfoDao;
import com.mef.smsplat.dao.base.DataGridModel;
import com.mef.smsplat.dao.base.EntityDao;
import com.mef.smsplat.dao.base.Page;
import com.mef.smsplat.domain.SysAdminInfoDomain;
import com.mef.smsplat.service.base.BaseService;

@Service
@Transactional
public class SysAdminInfoService extends BaseService<SysAdminInfoDomain, String> {
	
	private SysAdminInfoDao sysAdminInfoDao;
	
	/**增加setXXXX()方法,spring就可以通过autowire自动设置对象属性,请注意大小写*/
	public void setSysAdminInfoDao(SysAdminInfoDao sysAdminInfoDao) {
		this.sysAdminInfoDao = sysAdminInfoDao;
	}

	@Override
	public EntityDao getEntityDao() {
		return this.sysAdminInfoDao;
	}
	
	/**
	 * 登录
	 * @param username
	 * @param password
	 * @return
	 */
	public SysAdminInfoDomain login(String username,String password){
		SysAdminInfoDomain admin = sysAdminInfoDao.query(username, password);
		//这里可以做其他业务逻辑处理
		if(admin != null){
			admin.setLoginTime(new Date());
			save(admin);
		}
		return admin;
	}
	
	/**
	 * 分页查询
	 * @param adminName
	 * @param dgm
	 * @return
	 */
	@Transactional(readOnly=true)
	public Page<SysAdminInfoDomain> query(String adminName,DataGridModel dgm){
		return sysAdminInfoDao.query(adminName, dgm);
	}
	
	/**
	 * 查询账号是否唯一
	 * @param name
	 * @param id
	 * @return
	 */
	@Transactional(readOnly=true)
	public boolean isUnique(String name, String id){
		boolean isUnique = sysAdminInfoDao.queryByNameAndId(name, id);
		return isUnique;
	}
}
